package com.socket.socketTest;

import java.io.*;
import java.net.Socket;

/**
 * PetClient--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2017-09-13 15:45
 **/
public class PetClient {

    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("localhost", 8787);
        OutputStream os = socket.getOutputStream();
        PrintWriter pw = new PrintWriter(os);

        String request = "您好，我有一条吉娃娃狗！";

        pw.write(request);
        pw.flush();

        socket.shutdownOutput();

        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String repay;
        while ((repay = br.readLine()) != null) {
            System.out.println("我是宠物主人，宠物店给我的回应：" + repay);
        }

        br.close();
        is.close();
        pw.close();
        os.close();
        socket.close();


    }
}
